package com.blockchain.console.servlets.trading.jysc;

import java.math.BigDecimal;
import java.sql.Timestamp;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.blockchain.common.enums.IsPass;
import com.blockchain.console.service.trading.TradingManage;
import com.blockchain.console.service.trading.entity.JyfqEntity;
import com.blockchain.console.service.trading.entity.JyscEntity;
import com.blockchain.console.service.trading.entity.XlbEntity;
import com.blockchain.console.service.trading.query.JyscQuery;
import com.blockchain.console.servlets.trading.AbstractTradingServlet;
import com.blockchain.framework.http.servlet.annotation.Right;
import com.blockchain.framework.resource.PromptLevel;
import com.blockchain.framework.service.ServiceSession;
import com.blockchain.util.parser.BigDecimalParser;
import com.blockchain.util.parser.EnumParser;
import com.blockchain.util.parser.IntegerParser;

@Right(id = "C_TRADING_UPDATEJYSC", name = "市场管理-编辑")
public class UpdateJysc extends AbstractTradingServlet {

	private static final long serialVersionUID = 1L;

	@Override
	protected void processGet(HttpServletRequest request, HttpServletResponse response, ServiceSession serviceSession)
			throws Throwable {
		int id = IntegerParser.parse(request.getParameter("id"));
		TradingManage tsradingManage = serviceSession.getService(TradingManage.class);
		XlbEntity[] xlb = tsradingManage.getXlbxx();
		JyfqEntity[] fq = tsradingManage.jyfqOnlySearch();
		JyscEntity jy = tsradingManage.getJysc(id);
		request.setAttribute("xlb", xlb);
		request.setAttribute("fq", fq);
		request.setAttribute("jy", jy);
		forwardView(request, response, getClass());

	}

	@Override
	protected void processPost(final HttpServletRequest request, final HttpServletResponse response,
			final ServiceSession serviceSession) throws Throwable {
		try {
			int id = IntegerParser.parse(request.getParameter("id"));
			TradingManage tsradingManage = serviceSession.getService(TradingManage.class);
			tsradingManage.updateJysc(new JyscQuery() {

				@Override
				public int getXsws() {
					return IntegerParser.parse(request.getParameter("xsws"));
				}
				
				public int getSlxsws() {
					return IntegerParser.parse(request.getParameter("slxsws"));
				}

				@Override
				public IsPass getSfxs() {
					return EnumParser.parse(IsPass.class, request.getParameter("sfxs"));
				}

				@Override
				public IsPass getSfkqjy() {
					return EnumParser.parse(IsPass.class, request.getParameter("sfkqjy"));
				}

				@Override
				public BigDecimal getMr_zxj() {
					return BigDecimalParser.parse(request.getParameter("mr_zxj"));
				}

				@Override
				public BigDecimal getMr_zdj() {
					return BigDecimalParser.parse(request.getParameter("mr_zdj"));
				}

				@Override
				public BigDecimal getMr_sxf() {
					return BigDecimalParser.parse(request.getParameter("mr_sxf"));
				}

				@Override
				public int getMr_bz() {
					return IntegerParser.parse(request.getParameter("mr_bz"));
				}

				@Override
				public BigDecimal getMc_zxj() {
					return BigDecimalParser.parse(request.getParameter("mc_zxj"));
				}

				@Override
				public BigDecimal getMc_zdj() {
					return BigDecimalParser.parse(request.getParameter("mc_zdj"));
				}

				@Override
				public BigDecimal getMc_sxf() {
					return BigDecimalParser.parse(request.getParameter("mc_sxf"));
				}

				@Override
				public int getMc_bz() {
					return IntegerParser.parse(request.getParameter("mc_bz"));
				}

				@Override
				public int getFqid() {
					return IntegerParser.parse(request.getParameter("fqid"));
				}

				@Override
				public Timestamp getCreateTimeStart() {
					return null;
				}

				@Override
				public Timestamp getCreateTimeEnd() {
					return null;
				}
			}, id);
			sendRedirect(request, response, getController().getURI(request, JyscList.class));
		} catch (Throwable e) {
			prompt(request, response, PromptLevel.ERROR, e.getMessage());
			processGet(request, response, serviceSession);
		}

	}

}
